import * as echarts from '../../ec-canvas/echarts.min';
const app = getApp();

function initChart(canvas, width, height, dpr) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(chart);

  var option = {
    backgroundColor: "#ffffff",
    color: ["#5DBFFF", "#5D5DF1"],
    tooltip: {
      trigger: 'item',
      formatter: '{b}: {c} ({d}%)'
  },
    series: [{
      label: {
        normal: {
          fontSize: 14
        }
      },
      type: 'pie',
      center: ['50%', '50%'],
      radius: ['40%', '60%'],
      data: [{
        value: app.globalData.taxation.cr,
        name: '出让方',
      }, {
        value: app.globalData.taxation.sr,
        name: '受让方'
      }]
    }]
  };

  chart.setOption(option);
  return chart;
}

Page({
  data: {
    ec: {
      onInit: initChart,
      // lazyLoad: true // 延迟加载
    }
  },
  onLoad(options){
    console.log(options)
    var info = JSON.parse(decodeURIComponent(options.data));
    info.cr =  Math.round(info.value_added_tax + info.individual_income_tax + info.land_value_added_tax + info.stamp_duty1 + info.land_transfer_fee)
    info.sr = Math.round( info.deed_tax + info.stamp_duty2 + info.register_price)
    info.value_added_tax = Math.round(info.value_added_tax)
    info.deed_tax = Math.round(info.deed_tax)
    info.stamp_duty2 = Math.round(info.stamp_duty2)
    info.register_price = Math.round(info.register_price)
    info.stamp_duty1 = Math.round(info.stamp_duty1)
    info.land_transfer_fee = Math.round(info.land_transfer_fee)
    info.land_value_added_tax = Math.round(info.land_value_added_tax)
    Math.round(info.deed_tax + info.stamp_duty2 + info.register_price)
    info.individual_income_tax = Math.round(info.individual_income_tax)
    info.transferor_total = Math.round(info.transferor_total)
    app.globalData.taxation.cr = info.cr
    app.globalData.taxation.sr = info.sr
    this.setData({
      info:info
    })
  },

  onReady() {
  }
});
